﻿using System.ComponentModel;
using System.Reflection;
using System;

namespace NMA.Web.Core.CustomAttributes
{
    using NMA.Web.Core.ResourceFactory;

    public class DBLocalizedDisplayNameAttribute : DisplayNameAttribute
    {
        private string _displayFunctionName;
        private Type _resourceFactory;

        public DBLocalizedDisplayNameAttribute(Type resourceFactory, string displayFunctionName)
       {
           _resourceFactory = resourceFactory;
           _displayFunctionName = displayFunctionName;
       }

        public override string DisplayName
        {
            get
            {
                Type ty = _resourceFactory;
                MethodInfo[] mi = ty.GetMethods();
                MethodInfo methodInfo = ty.GetMethod(_displayFunctionName);
                var o = Activator.CreateInstance(ty);
                var result = methodInfo.Invoke(o, null);
                return result.ToString();
            }
        }
    }
}